<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!-- Change password -->
            <div class="panel-body">
                <h1 class="login-title">修改密码</h1>
                    <div class="form-group">
                        <label>Old Password</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span> </span>
                            <input type="password" class="form-control" id="old-pwd" name="old-pwd" placeholder="Password...">
                        </div>
                        <span class="red-span" id="old-pwd-alert"></span>
                    </div>
                    <div class="form-group">
                        <label>New Password</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span> </span>
                            <input type="password" class="form-control" id="pwd" name="pwd" placeholder="Password...">
                        </div>
                        <span class="red-span" id="pwd-alert"></span>
                    </div>
                    <div class="form-group">
                        <label>New Password Confirm</label>
                        <div class="input-group">
                            <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span> </span>
                            <input type="password" class="form-control" id="new-pwd-con" name="new-pwd-con" placeholder="Password...">
                        </div>
                        <span class="red-span" id="pwd-con-alert"></span>
                    </div>
                    <div class="form-group">
                    	<span class="red-span" id="commit-btn-alert"></span>
                        <button type="button" class="btn btn-common login-btn" id="commit-btn">Commit</button>
                    </div>
                <!-- </form> -->
            </div>
            
            
            
            
            
<script type="text/javascript">

	 $(function(){
		 
		 $("#old-pwd").blur(function(){
			 $.ajax({
	              url:"checkPwd",
	              type:"post",
	              data:{old:$("#old-pwd").val()},
	              success:function(d){
	            	  if(!d.status){
	            		  $("#old-pwd-alert").html("对不起，旧密码有误！！请重新输入！");
	            	  }else{
	            		  $("#old-pwd-alert").empty();
	            	  }
	              }
	          })
		 });
		 
		 $("#new-pwd-con").blur(function(){
			 if($("#new-pwd-con").val() != $("#pwd").val() || $("#new-pwd-con").val() == ''){
					$("#pwd-con-alert").html("两次密码输入不一致！");
				}
		 });
		 
		 $("input").focus(function(){
				$("#commit-btn-alert").html("");
				$("#pwd-con-alert").html("");
		 });
		 
		 
		//表单提交时验证
			$("#commit-btn").click(function checkForm() {
				//所有验证通过，则i为true，返回i
				var i = true;
				
				$("input").trigger("blur");
				$(".red-span").each(function() {
					if ($(this).html() != "") {
						$("#commit-btn-alert").html("请完整填写表单！");
						i = false;
					}
				})
					if(i == true){
						$.ajax({
				              url:"changePwd",
				              type:"post",
				              data:{pwd:$("#pwd").val()},
				              success:function(d){
				            	  if(d.status){
				            		  $("#commit-btn-alert").html("恭喜，修改成功！");
				            		  /* window.location.href = "${pageContext.request.contextPath}/homes/info"; */
				            		  i = false;
				            	  }
				              }
				          })
					}
						
				return i;
				
			})

		 
		 
		 
		/* $("#commit-btn").on("click",function(){
			
          $.ajax({
              url:"changePwd",
              type:"post",
              data:{pwd:$("#pwd").val()},
              success:function(d){
            	  if(d.status){
            		  alert("修改成功！");
            		  window.location.href = "${pageContext.request.contextPath}/home";
            	  }else{
            		  $("#login-alert").html("对不起，修改失败！");
            	  }
              }
          })
      	}); */
		
	}); 
	
</script>